package licode.unisop.types.dp;

import org.springframework.util.Assert;

/**
 * 地址状态
 */
public class UrlState {

    public static final UrlState NORMAL = new UrlState(0);
    public static final UrlState PUBLIC = new UrlState(1);
    public static final UrlState DISABLE = new UrlState(2);
    public static final UrlState NO_EXIST = new UrlState(8);

    private final int state;

    private UrlState(int state) {
        this.state = state;
    }

    public static UrlState build(int state) {
        Assert.isTrue(state == 0 || state == 1 || 2 == state,
                "地址状态取值0、1或2，当前：" + state);
        if (UrlState.NORMAL.state == state) {
            return UrlState.NORMAL;
        } else if (UrlState.PUBLIC.state == state) {
            return UrlState.PUBLIC;
        } else if (UrlState.NO_EXIST.state == state) {
            return UrlState.NO_EXIST;
        }
        return UrlState.DISABLE;
    }

    public boolean isNoExist() {
        return (UrlState.NO_EXIST.state == state);
    }

    public boolean isNormal() {
        return (UrlState.NORMAL.state == state);
    }

    public boolean isPublic() {
        return (UrlState.PUBLIC.state == state);
    }

    public boolean isDisable() {
        return (UrlState.DISABLE.state == state);
    }

    public int getState() {
        return state;
    }

    @Override
    public String toString() {
        return state + "";
    }
}
